package com.epichust.bootumpp.controller;

import com.epichust.bootumpp.model.bo.ReturnBO;
import com.epichust.bootumpp.model.entity.Umpp5WorkOrder;
import com.epichust.bootumpp.service.IUmpp5WorkOrderService;
import com.epichust.bootumpp.service.impl.Umpp5WorkOrderServiceImpl;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author ：pengmin
 * @date ：Created in 2020/12/29
 * @description：工单控制层
 */
@RestController
@RequestMapping("/pm/workOrder")
public class Umpp5WorkOrderController {

    @Autowired
    public IUmpp5WorkOrderService iUmpp5WorkOrderService;


    @RequestMapping(value = "/getAllUmpp5WorkOrder", method = {RequestMethod.POST})
    public String getAllUmpp5WorkOrder(@RequestBody Map<String,String> map) throws Exception{
        try{
            // 新建返回对象
            Gson gson = new GsonBuilder().serializeNulls().create();
            List<Umpp5WorkOrder> list= iUmpp5WorkOrderService.getAllUmpp5WorkOrder(map);
            ReturnBO bo = new ReturnBO();
            bo.setState(0);
            bo.setObject(list);
            return gson.toJson(bo);
        }catch(Exception e){
            e.printStackTrace();
            Gson gson = new GsonBuilder().serializeNulls().create();
            ReturnBO bo = new ReturnBO();
            bo.setState(1);
            bo.setObject("查询失败："+e.getMessage());
            return gson.toJson(bo);
        }
    }
}
